﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.DAL;
using Gift.Model;

namespace WebSite.cn
{
    public partial class ValidateCard : BasePage
    {


        readonly Card theCard = new Card();
        readonly OrderAccount theOrderAccount = new OrderAccount();
        readonly DALShoppro theShoppro = new DALShoppro();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               // this.divErrorMessage.Attributes["style"] = "display:none;";
            }
        }


        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            //this.divErrorContent.InnerHtml = string.Empty;
            //string sMessageStyle = "position:absolute;margin-left:300px;  background-color:#fff; float:right; width:300px; height:140px; margin-top:10px;  display:block; border:2px solid red;";

            //if (string.IsNullOrEmpty(this.txtCardCode.Text.Trim()))
            //{
            //    this.divErrorContent.InnerHtml = "卡号不能为空！";
            //    this.divErrorMessage.Attributes["style"] = sMessageStyle;
            //    return;
            //}
            //if (string.IsNullOrEmpty(this.txtPassword.Text.Trim()))
            //{
            //    this.divErrorContent.InnerHtml = "密码不能为空！";
            //    this.divErrorMessage.Attributes["style"] = sMessageStyle;
            //    return;
            //}
            //if (string.IsNullOrEmpty(this.txtValidate.Text.Trim()))
            //{
            //    this.divErrorContent.InnerHtml = "验证码不能为空！";
            //    this.divErrorMessage.Attributes["style"] = sMessageStyle;
            //    return;
            //}

            //if (string.Compare(this.txtValidate.Text.Trim(), Session["checkCode"].ToString()) != 0)
            //{
            //    this.divErrorContent.InnerHtml = "验证码不正确，请重新输入！";
            //    this.divErrorMessage.Attributes["style"] = sMessageStyle;
            //    return;
            //}

            try
            {
                dbCard oCard;
                oCard = theCard.GetModel(this.txtCardCode.Value.Trim(), this.txtPassword.Value.Trim());
                if (oCard != null)
                {


                    DALCardType theCardType = new DALCardType();
                    DALProfessionAreaType theProfessionAreaType = new DALProfessionAreaType();
                    tbCardType oCardType = new tbCardType();
                    tbProfessionAreaType oProfessionAreaType = new tbProfessionAreaType();
                    oCardType = theCardType.GetModel(oCard.cardtypeId);
                    oProfessionAreaType = theProfessionAreaType.GetModel(oCardType.ProfessionAreaTypeId);
                    this.lblMessage.Text = "<div style='width:100%;text-align:left;line-height:20px;'> 卡片类别:" + oCardType.Name + ";<br/>所属专区:" + oProfessionAreaType.Name + ";<br/>卡内金额:" + oCard.cardprice.ToString()
                                          + " <br/> 专区有效时间：" + oCard.StartTime.ToString("yyyy-MM-dd") + " 至" + oCard.endtime.ToString("yyyy-MM-dd") + ";";
                    if (oCard.lasttime > oCard.endtime)
                    {
                        this.lblMessage.Text = this.lblMessage.Text
                                                  + " <br/> 礼品商城有效时间为：" + oCard.endtime.AddDays(1).ToString("yyyy-MM-dd") + " 到 " + oCard.lasttime.ToString("yyyy-MM-dd");
                    }

                    if (oCard.states == 0)
                    {
                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡还未激活，请先开卡后才能使用！";
                    }
                    else if (oCard.states == 2)
                    {
                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已被使用！";
                    }
                    else if (oCard.states == 3)
                    {
                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已过了兑换有效日期！";
                    }
                    else if (oCard.states == 4)
                    {
                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡还未激活,请先开卡后才能使用！";
                    }
                    else if (oCard.endtime < DateTime.Now)
                    {
                        if (oCard.lasttime >= DateTime.Now)
                        {
                            this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡的专区有效时间已过,只能到礼品商城兑换商品！";
                        }
                        else
                        {
                            this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已过了兑换有效日期！";
                        }
                    }
                    else if (oCard.states == 1)
                    {

                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡可以正常使用！";

                    }
                    else
                    {
                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已被使用！";
                    }
                    this.lblMessage.Text = this.lblMessage.Text + "</div>";
                }
                else
                {
                    this.lblMessage.Text = this.lblMessage.Text + "<br/>卡号或密码不正确！";
                    return;
                }
            }catch
            {
                this.lblMessage.Text = this.lblMessage.Text + "<br/>卡号或密码不正确！";
                return;
            }
        }


    }
}